package org.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * @author 莫磊
 * @date 2025/8/11
 * @description
 */
@Slf4j
@Controller
public class FileController {

	@GetMapping("file")
	public String file() {
		return "file-upload";
	}

	@PostMapping("/fileUpload")
	@ResponseBody
	public ResponseEntity<String> upload(@RequestParam("file") MultipartFile file) throws IOException {
		// file.transferTo(new File("D:/" + file.getOriginalFilename()));
		// HttpHeaders headers = new HttpHeaders();
		// headers.set("Content-Type","text/html;charset=UTF-8");
		// ResponseEntity<String> responseEntity = new ResponseEntity<>("上传成功", headers, HttpStatus.OK);
		// System.out.println(file.getName());
		// System.out.println(file.getOriginalFilename());
		// return responseEntity;
		return ResponseEntity.ok("上传成功");
	}

	@GetMapping("/error")
	public String error() {
		int i = 1/0;
		return "index";
	}
}
